package cn.kongwg.es.controller;

import cn.kongwg.es.entity.JBook;
import cn.kongwg.es.service.JBookService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.awt.print.Book;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author kongwg
 * @create 2021-04-02 19:43
 */
@RestController
public class JBookController {

    @Autowired
    private JBookService jBookService;


    @GetMapping("/parse/{keyword}")
    public List<Map<String, Object>> getJBooks(@PathVariable("keyword") String keyword) {
        List<Map<String,Object>> books = null;
        try {
            books = jBookService.getBooks(keyword);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return books;
    }


    @GetMapping("/test")
    public List<Map> getlist(){

        List<Map> list = new ArrayList<>();
        Map map = new HashMap();
        map.put("kongwg","shuage");
        list.add(map);
        return list;
    }

}
